/*
  员工列表: /employee,
  入离职管理: /management,
  部门管理: /department,
  员工调动: /transfer
*/
// let dataStr = "员工列表: /employee_list, 入离职管理: /management, 部门管理: /department, 员工调动: /transfer";

/**
 * @description 将如上字符串形式转化为json格式
 * @param null
 * @returns {String}
 */
export function convert(dataStr){
  let datas = dataStr.split(',');
  let ans = [];
  for (let data of datas) {
    let obj = {};
    data = data.trim();
    let split_arr = data.split(':');
    obj.name = split_arr[0].trim();
    obj.path = split_arr[1].trim();
    ans.push(obj);
  }
  // console.log(ans);
  return ans;
}

// console.log(convert(dataStr));
/*
  [
    {name: '员工列表', path: '/employee_list'},
    {name: '入离职管理', path: '/management'},
    {name: '部门管理', path: '/department'},
    {name: '员工调动', path: '/transfer'}
  ]
*/


/**
 * @description 获取调用时当天的日期
 * @returns {string}
 */
export function getNowDate() {
  let year = new Date().getFullYear();
  let month = new Date().getMonth() + 1 < 10
      ? "0" + (new Date().getMonth() + 1)
      : new Date().getMonth() + 1;
  let date = new Date().getDate() < 10
      ? "0" + new Date().getDate()
      : new Date().getDate();
  // console.log(year + " " + month + " " + date); 2022 06 25
  const nowTime = year + "-" + month + "-" + date;
  return nowTime;
}

/**
 * @description 防抖函数，用于输入实时获取数据库信息
 * @param func
 * @param delay
 * @returns {Function}
 */
export function debounce(func, delay) {
  let timer = null;
  return function () {
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      func.apply(this, arguments)
    }, delay)
  }
}

/**
 * @description 根据 id 自动获取生日
 * @param id
 * @returns {string}
 */
export function computeBirth(id) {
  // 130125 20020123 0012 身份证号第6位到第14位为生日
  const str = id.substring(6, 14);
  // console.log(str);
  const y = str.substring(0, 4),
      m = str.substring(4, 6),
      d = str.substring(6, 8);
  // console.log(y, m, d);
  return y + '-' + m + '-' + d;
}